netfilter: nf_tables: fix set->nelems counting with no NLM_F_EXCL
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 23 Jan 2017 23:51:32 +0000 (00:51 +0100)
committerRaspbian kernel package updater <root@raspbian.org>
Sun, 23 Jul 2017 02:59:31 +0000 (02:59 +0000)
commite8ebd6d77f0dcdff8b30c0c9ba508d07885a9353
tree70464461ebe419bbdf82b244d21c26e109a21094
parent77e2eeddaef83ada7e92c06d739f0108f236f94c
netfilter: nf_tables: fix set->nelems counting with no NLM_F_EXCL

[ Upstream commit 35d0ac9070ef619e3bf44324375878a1c540387b ]

If the element exists and no NLM_F_EXCL is specified, do not bump
set->nelems, otherwise we leak one set element slot. This problem
amplifies if the set is full since the abort path always decrements the
counter for the -ENFILE case too, giving one spare extra slot.

Fix this by moving set->nelems update to nft_add_set_elem() after
successful element insertion. Moreover, remove the element if the set is
full so there is no need to rely on the abort path to undo things
anymore.

Fixes: c016c7e45ddf ("netfilter: nf_tables: honor NLM_F_EXCL flag in set element insertion")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netfilter/nf_tables_api.c